﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class UserLogin : Form
    {
        DAL sqlHelp = new DAL();
        public UserLogin()
        {
            InitializeComponent();
            txt_worknum.Text = "100139";
            txt_pwd.Text = "Yuquan305";
        }

        private void btn_exit_Click(object sender, EventArgs e)
        {
            DialogResult result= MessageBox.Show("是否退出系统？","询问",MessageBoxButtons.OKCancel,MessageBoxIcon.Question);
            if (result == DialogResult.OK) 
            {
              //  this.Close();
                Application.Exit();
            }
        }

        /// <summary>
        /// 登陆按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_login_Click(object sender, EventArgs e)
        {
            string worknum = txt_worknum.Text;
            string pwd = txt_pwd.Text;
            if (txt_worknum.Text == null || txt_worknum.Text == "")
            {
                MessageBox.Show("工号不能为空，请重新输入！", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (txt_pwd.Text == null || txt_pwd.Text == "") 
            {
                MessageBox.Show("密码不能为空，请重新输入！", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            string name=sqlHelp.CheckLogin(worknum,pwd);
            if(name==null||name=="") 
            {
                MessageBox.Show("工号或密码错误，请重新输入！","警告",MessageBoxButtons.OK,MessageBoxIcon.Warning);
                txt_pwd.Text = "";
                return;
            }
               weeklyreport frm = new weeklyreport(name);
                frm.Show();
                this.Hide();
            
        }

        private void txt_pwd_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                btn_login_Click(sender,e);
            }
            if (e.KeyCode == Keys.Escape)
            {
                btn_exit_Click(sender, e);
            }
        }

        private void UserLogin_Activated(object sender, EventArgs e)
        {
            txt_worknum.Focus();
        }


        private void txt_worknum_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                btn_login_Click(sender, e);
            }
            if (e.KeyCode == Keys.Escape)
            {
                btn_exit_Click(sender, e);
            }
        }
    }
}
